﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LuaFramework;
using LuaInterface;

namespace LuaFramework {

	/// <summary>
	/// 用于3d碰撞
	/// </summary>
	public class LuaCollision3DComponent : LuaComponent {

		void OnCollisionEnter(Collision collision)
		{
			if (!string.IsNullOrEmpty(_name))
			{
				if (!LuaManager.IsInited || _table==null) return;

				LuaFunction func = _table.GetLuaFunction("OnCollisionEnter");
				if (func != null)
				{
					func.Call(_table,collision);
					func.Dispose();
					func = null;
				}
			}
		}

		void OnCollisionExit(Collision collision)
		{
			if (!string.IsNullOrEmpty(_name))
			{
				if (!LuaManager.IsInited || _table==null) return;

				LuaFunction func = _table.GetLuaFunction("OnCollisionExit");
				if (func != null)
				{
					func.Call(_table,collision);
					func.Dispose();
					func = null;
				}
			}
		}

		void OnCollisionStay(Collision collision)
		{
			if (!string.IsNullOrEmpty(_name))
			{
				if (!LuaManager.IsInited || _table==null) return;

				LuaFunction func = _table.GetLuaFunction("OnCollisionStay");
				if (func != null)
				{
					func.Call(_table,collision);
					func.Dispose();
					func = null;
				}
			}
		}

		void OnTriggerEnter(Collider collider)
		{
			if (!string.IsNullOrEmpty(_name))
			{
				if (!LuaManager.IsInited || _table==null) return;

				LuaFunction func = _table.GetLuaFunction("OnTriggerEnter");
				if (func != null)
				{
					func.Call(_table,collider);
					func.Dispose();
					func = null;
				}
			}
		}

		void OnTriggerStay(Collider collider)
		{
			if (!string.IsNullOrEmpty(_name))
			{
				if (!LuaManager.IsInited || _table==null) return;

				LuaFunction func = _table.GetLuaFunction("OnTriggerStay");
				if (func != null)
				{
					func.Call(_table,collider);
					func.Dispose();
					func = null;
				}
			}
		}

		void OnTriggerExit(Collider collider)
		{
			if (!string.IsNullOrEmpty(_name))
			{
				if (!LuaManager.IsInited || _table==null) return;

				LuaFunction func = _table.GetLuaFunction("OnTriggerExit");
				if (func != null)
				{
					func.Call(_table,collider);
					func.Dispose();
					func = null;
				}
			}
		}

		void OnJointBreak(float breakForce)
		{
			if (!string.IsNullOrEmpty(_name))
			{
				if (!LuaManager.IsInited || _table==null) return;

				LuaFunction func = _table.GetLuaFunction("OnJointBreak");
				if (func != null)
				{
					func.Call(_table,breakForce);
					func.Dispose();
					func = null;
				}
			}
		}
    }
}